layui.use(['element', 'code'], function(){
    var element = layui.element,
        code = layui.code;

    element.on('nav(apidesc)',function(data){
        let layId = this.getAttribute('lay-id');
        let tabId = Number(Math.random().toString().substr(3,10) + Date.now()).toString(36);
        if (layId) {
            //点击添加Tab选项卡
            element.tabAdd('infoTab',{
                title: data.context.innerText,
                //此处动态嵌入iframe
                content:'<iframe id="iframe" scrolling="yes" style="width:100%;height:100%" frameborder="0" src="/admin/api/show?id=' + layId + '" class="x-iframe"></iframe>',
                id: tabId
            });
            element.tabChange('infoTab', tabId);
        }
    });

    layui.code({
        title: 'json'
    });

});
